/*
 *  src/process_control/fifo.c
 *
 *  Harry Wei <harryxiyou@gmail.com> (C) 2011
 */
#include <glib.h>
#include <unistd.h>
#include <stdint.h>
#include <stdlib.h>

#define BUFSIZE (100)
#if 0
int unnamed_pipe(void)
{
	int fd[2];
	static char message[BUFSIZ];
	static char w_buf[BUFSIZ] = "This is unnamed pipe";

	g_message("%s -- BUFSIZ: %d", BUFSIZ);
	memset(message, 0, BUFSIZE);
	memset(w_buf, 0, BUFSIZE);
	if (-1 == pipe(fd)) {
		g_message("%s -- pipe error!", __func__);
		return -1;
	}
	switch (fork()) {
		case -1:
			g_message("%s -- fork error!", __func__);
			exit(EXIT_FAILURE);
		case 0:
			close(fd[1]);
			if (-1 == read(fd[0], message, BUFSIZ)) {
				g_message("%s -- read error!", __func__);
				exit(EXIT_FAILURE);
			}
			g_message("%s -- received by child are [%s]", message);
			fflush(stdout);
			exit(EXIT_SUCCESS);
		default:
			close(fd[0]);
			if (-1 == write(fd[1], w_buf, BUFSIZ)) {
				g_message("%s -- read error!", __func__);
				exit(EXIT_FAILURE);
			}
			g_message("%s -- sent by parent are [%s]", w_buf);
			fflush(stdout);
			exit(EXIT_SUCCESS);
	}
	exit(EXIT_SUCCESS);
}
#endif
